﻿using LeHouse.Server.Dto;
using LeHouse.Server.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace LeHouse.Server.WebApi.Controllers
{
    public class OwnershipController : ApiController
    {
        /// <summary>
        /// 房屋所有权证书表的回填显示
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/GetOwner")]
        public dynamic GetOwner([FromBody]string[] parms)
        {
            Collateral_ownershipService bllOwner = new Collateral_ownershipService();
            System_DictionaryService blldic = new System_DictionaryService();
            List<dynamic> datas = new List<dynamic>();
            Collateral_ownership Owner = bllOwner.Select(t => t.T_ReportNumber == parms[0]).FirstOrDefault();
            datas.Add(Owner);
            for (int i = 1; i < parms.Length; i++)
            {
                int Dmenuid = Convert.ToInt32(parms[i]);
                List<System_Dictionary> droplist = blldic.Select(p => p.Dmenuid == Dmenuid);
                datas.Add(droplist);
            }

            return datas;
        }

        /// <summary>
        /// 房屋所有权证书表的操作
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/InsertOrUpdateOwner")]
        public bool InsertOrUpdateOwner([FromBody]Collateral_ownership tax)
        {
            Collateral_ownershipService bll = new Collateral_ownershipService();
            var ss = bll.Select(p => p.T_ReportNumber == tax.T_ReportNumber).Count();
            if (ss != 0)
            {
                if (bll.Delete(p => p.T_ReportNumber == tax.T_ReportNumber) == true)
                {
                    if (bll.Insert(tax) == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

            }
            else
            {
                if (bll.Insert(tax) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }

        }
        /// <summary>
        /// 不动产权证书表的信息回填
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/GetRea")]
        public dynamic GetRea([FromBody]string[] parms)
        {
            Collateral_RealestateService bllOwner = new Collateral_RealestateService();
            System_DictionaryService blldic = new System_DictionaryService();
            List<dynamic> datas = new List<dynamic>();
            Collateral_Realestate Owner = bllOwner.Select(t => t.T_ReportNumber == parms[0]).FirstOrDefault();
            datas.Add(Owner);
            for (int i = 1; i < parms.Length; i++)
            {
                int Dmenuid = Convert.ToInt32(parms[i]);
                List<System_Dictionary> droplist = blldic.Select(p => p.Dmenuid == Dmenuid);
                datas.Add(droplist);
            }

            return datas;
        }

        /// <summary>
        /// 不动产权证书表信息的操作
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/InsertOrUpdateRea")]
        public bool InsertOrUpdateRea([FromBody]Collateral_Realestate tax)
        {
            Collateral_RealestateService bll = new Collateral_RealestateService();
            var ss = bll.Select(p => p.T_ReportNumber == tax.T_ReportNumber).Count();
            if (ss != 0)
            {
                if (bll.Delete(p => p.T_ReportNumber == tax.T_ReportNumber) == true)
                {
                    if (bll.Insert(tax) == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

            }
            else
            {
                if (bll.Insert(tax) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
        }







        /// <summary>
        /// 中华人民共和国税收完税证明表的回填显示
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/GetTax")]
        public Collateral_Taxcertificate GetTax([FromBody] string ReportNumber)
        {
            Collateral_TaxcertificateService bll = new Collateral_TaxcertificateService();
            Collateral_Taxcertificate tax = bll.Select(t => t.T_ReportNumber == ReportNumber).FirstOrDefault();
            return tax;
        }
        /// <summary>
        /// 中华人民共和国税收完税证明表的操作
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/InsertOrUpdateTax")]
        public bool InsertOrUpdateTax([FromBody]Collateral_Taxcertificate tax)
        {
            Collateral_TaxcertificateService bll = new Collateral_TaxcertificateService();
            var ss = bll.Select(p => p.T_ReportNumber == tax.T_ReportNumber).Count();
            if (ss != 0)
            {
                if (bll.Delete(p => p.T_ReportNumber == tax.T_ReportNumber) == true)
                {
                    if (bll.Insert(tax) == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

            }
            else
            {
                if (bll.Insert(tax) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
        }


        /// <summary>
        /// 存量房屋买卖合同表的信息回填
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/GetBus")]
        public dynamic GetBus([FromBody]string[] parms)
        {
            Collateral_BusinessContractService bllOwner = new Collateral_BusinessContractService();
            System_DictionaryService blldic = new System_DictionaryService();
            List<dynamic> datas = new List<dynamic>();
            Collateral_BusinessContract Owner = bllOwner.Select(t => t.T_ReportNumber == parms[0]).FirstOrDefault();
            datas.Add(Owner);
            for (int i = 1; i < parms.Length; i++)
            {
                int Dmenuid = Convert.ToInt32(parms[i]);
                List<System_Dictionary> droplist = blldic.Select(p => p.Dmenuid == Dmenuid);
                datas.Add(droplist);
            }

            return datas;
        }

        /// <summary>
        /// 存量房屋买卖合同表信息的操作
        /// </summary>
        /// <param name="ReportNumber"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Ownership/InsertOrUpdateBus")]
        public bool InsertOrUpdateBus([FromBody]Collateral_BusinessContract tax)
        {
            Collateral_BusinessContractService bll = new Collateral_BusinessContractService();
            var ss = bll.Select(p => p.T_ReportNumber == tax.T_ReportNumber).Count();
            if (ss != 0)
            {
                if (bll.Delete(p => p.T_ReportNumber == tax.T_ReportNumber) == true)
                {
                    if (bll.Insert(tax) == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

            }
            else
            {
                if (bll.Insert(tax) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }

        }
    }
}
